package com.xhs.zdl.demo.citypickerview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xhs.zdl.demo.R;

import java.util.List;

/**
 * Created by zdl on 2017/10/18.
 * email zdl328465042@163.com
 */

public class NormalListViewAdapter extends BaseAdapter {
    private Context context;
    private List<String> data;
    private LayoutInflater inflater;

    public NormalListViewAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public String getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        HomeViewHolder holder;
        if (null == view){
            holder = new HomeViewHolder();
            view = inflater.inflate(R.layout.home_listview_item, null);
            holder.tv = view.findViewById(R.id.home_tv);

            view.setTag(holder);
        }else
            holder = (HomeViewHolder) view.getTag();

        holder.tv.setText(data.get(i));
        holder.tv.setTag(data.get(i));

        return view;
    }

    class HomeViewHolder{
        TextView tv;
    }
}
